//
//  UIBarButtonItem+extension.swift
//  SinaWeibo
//
//  Created by Jiang on 2016/11/23.
//  Copyright © 2016年 Jiang. All rights reserved.
//

import UIKit


extension UIBarButtonItem{
   
    // 创建 UIbarButtonItem
    // - parameter title : title
    // - parameter fontSize : fontSize， 默认 16 号字
    // - parameter target: target 
    // - parameter action : action
    //- parameter isBack :  是否是返回按钮，如果是加上箭头
    
    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject?, action: Selector, isBackButton:Bool = false){
        
        
        let btn : UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBackButton {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action , for: .touchUpInside)
        
        //实例化 UIBarButtonItem
        self.init(customView: btn)
    }
    
}

